<template>
	<view>
		<uni-nav-bar left-icon="back"  right-text="发布"  :status-bar="true" @clickLeft="back" @clickRight="submit">
			<view class="f_center" @tap="changelook">
				{{this.yinsi}}
				<view class="icon iconfont icon-xialazhankai"></view>
			</view>
		</uni-nav-bar>
		<view class="uni-textarea">
			<textarea v-model="text" placeholder="说一句话吧~" />
		</view>
		<!-- 上传多图 -->
		<upload-images @upload="upload"></upload-images>
			<button @click="open">打开弹窗</button>
		<uni-popup ref="popup" type="center">
			<view class="popup-content">
				<image src="../../static/common/addinput.png" mode="widthFix" class="f_center"></image>
				<view>1、涉及黄色，政治，广告及骚扰信息</view>
				<view>2、涉及人身攻击</view>
				<view>3、留联系方式，透露他人隐私</view>
				<view>一经核实将被封禁，情节严重者永久封禁</view>
				<button @tap="popupHide">朕知道了</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import uniNavBar from '../../components/uni-nav-bar/uni-nav-bar.vue';
	import uploadImages from '../../components/common/uoload-images.vue';
	import uniPopup from '../../components/uni-popup/uni-popup-dialog.vue';
	export default {
		components:{
			uniNavBar,
			uploadImages
		},
		data() {
			return {
				yinsi: '所有人可见',
				lookList: ['所有人可见','仅自己可见'],
				text: '',
				imageList: [],
				showpopup: true,
				isget: false
			}
		},
		onReady(){
			this.$refs.popup.open();
		},
		onBackPress(){
			if(this.text==''&&this.imageList.length<1){ return; }
			if(!this.isget){
				this.baocun()
				return true;
			}
			
		},
		methods: {
			baocun(){
				uni.showModal({
					content:"是否要保存为草稿？",
					cancelText:"不保存",
					confirmText:"保存",
					success: res=>{
						if(res.confirm){
							console.log('保存')
						}else{
							console.log('不保存')
						}			
						this.isget = true;
						uni.navigateBack({
							delta: 1
						})
					}
				})
			},
			back(){
				uni.navigateBack({delta: 1})
			},
			submit(){
				console.log('发布信息')
			},
			changelook(){
				uni.showActionSheet({
					itemList: this.lookList,
					success: res=>{
						console.log(res.tapIndex)
						switch(res.tapIndex){
							case 0:
								this.yinsi = this.lookList[res.tapIndex]; 
								break;
							case 1:
								this.yinsi = this.lookList[res.tapIndex];
								break;
						}
					}
				})
			},
			upload(images){
				this.imageList = images;
			},
			open(){
				this.$refs.popup.open();
			},
			popupHide(){
				this.$refs.popup.close();
			}			
		}
	}
</script>

<style>
.uni-textarea>textarea{
	border: 1upx solid #eee;
}
.popup-content{
	background-color: #fff;
	padding: 40upx;
}
.popup-content image{
	width: 50%;
	margin: auto;
}
.popup-content>view{
	margin-top: 10upx;
}
.popup-content button{
	background-color: #FFE934;
	margin-top: 20upx;
}
</style>
